/*     */ package com.zimbra.cs.account.ldap.entry;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AttributeClass;
/*     */ import com.zimbra.cs.account.AttributeManager;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Signature;
/*     */ import com.zimbra.cs.ldap.LdapUtil;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class LdapSignatureBase
/*     */   extends Signature
/*     */   implements LdapEntry
/*     */ {
/*     */   protected LdapSignatureBase(Account acct, String name, String id, Map<String, Object> attrs, Provisioning prov)
/*     */   {
/*  39 */     super(acct, name, id, attrs, prov);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private static boolean hasAccountSignature(Account acct)
/*     */   {
/*  58 */     return (acct.getAttr("zimbraPrefMailSignature") != null) || (acct.getAttr("zimbraSignatureName") != null) || (acct.getAttr("zimbraSignatureId") != null);
/*     */   }
/*     */   
/*     */   public static Signature getAccountSignature(Provisioning prov, Account acct)
/*     */     throws ServiceException
/*     */   {
/*  64 */     if (!hasAccountSignature(acct)) {
/*  65 */       return null;
/*     */     }
/*  67 */     Map<String, Object> attrs = new HashMap();
/*  68 */     Set<String> signatureAttrs = AttributeManager.getInstance().getAttrsInClass(AttributeClass.signature);
/*     */     
/*  70 */     for (String name : signatureAttrs) {
/*  71 */       String value = acct.getAttr(name, null);
/*  72 */       if (value != null) {
/*  73 */         attrs.put(name, value);
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*  79 */     Map<String, Object> putbackAttrs = new HashMap();
/*  80 */     String sigName = acct.getAttr("zimbraSignatureName");
/*  81 */     if (sigName == null) {
/*  82 */       sigName = acct.getName();
/*  83 */       putbackAttrs.put("zimbraSignatureName", sigName);
/*     */     }
/*  85 */     String sigId = acct.getAttr("zimbraSignatureId");
/*  86 */     if (sigId == null) {
/*  87 */       sigId = LdapUtil.generateUUID();
/*  88 */       putbackAttrs.put("zimbraSignatureId", sigId);
/*     */     }
/*  90 */     if (putbackAttrs.size() > 0) {
/*  91 */       prov.modifyAttrs(acct, putbackAttrs);
/*     */     }
/*  93 */     return new Signature(acct, sigName, sigId, attrs, prov);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static boolean isAccountSignature(Account acct, String signatureId)
/*     */   {
/* 101 */     String acctSigId = acct.getAttr("zimbraSignatureId");
/* 102 */     return signatureId.equals(acctSigId);
/*     */   }
/*     */   
/*     */   public static void modifyAccountSignature(Provisioning prov, Account acct, Map<String, Object> signatureAttrs) throws ServiceException {
/* 106 */     prov.modifyAttrs(acct, signatureAttrs);
/*     */   }
/*     */   
/*     */   public static void createAccountSignature(Provisioning prov, Account acct, Map<String, Object> signatureAttrs, boolean setAsDefault) throws ServiceException {
/* 110 */     if (setAsDefault) {
/* 111 */       String signatureId = (String)signatureAttrs.get("zimbraSignatureId");
/* 112 */       signatureAttrs.put("zimbraPrefDefaultSignatureId", signatureId);
/*     */     }
/* 114 */     prov.modifyAttrs(acct, signatureAttrs);
/*     */   }
/*     */   
/*     */   public static void deleteAccountSignature(Provisioning prov, Account acct) throws ServiceException {
/* 118 */     Map<String, Object> attrs = new HashMap();
/* 119 */     Set<String> signatureAttrs = AttributeManager.getInstance().getAttrsInClass(AttributeClass.signature);
/*     */     
/* 121 */     for (String name : signatureAttrs) {
/* 122 */       String value = acct.getAttr(name, null);
/* 123 */       if (value != null) { attrs.put("-" + name, value);
/*     */       }
/*     */     }
/* 126 */     prov.modifyAttrs(acct, attrs);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/entry/LdapSignatureBase.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */